<?php
class ProductCategoriesController extends StoreAppController {

	var $name = 'StoreProductCategories';
	var $permissions = array(
		'add' => array('admin','manag'),
		'index' => array('admin','manag'),
		'edit' => array('admin','manag'),
		'delete' => array('admin','manag'),
		'view' => array('admin','manag')
	);
	
	public function beforeFilter(){
		parent::beforeFilter();
		$this->layout = 'cms';
	}
	
	function index() {
		$this->StoreProductCategory->recursive = 0;
		$this->set('storeProductCategories', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__d('store','Invalid store product category', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('storeProductCategory', $this->StoreProductCategory->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->StoreProductCategory->create();
			if ($this->StoreProductCategory->save($this->data)) {
				$this->Session->setFlash(__d('store','The store product category has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__d('store','The store product category could not be saved. Please, try again.', true));
			}
		}
		$storeProducts = $this->StoreProductCategory->StoreProduct->find('list');
		$storeCategories = $this->StoreProductCategory->StoreCategory->find('list');
		$this->set(compact('storeProducts', 'storeCategories'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__d('store','Invalid store product category', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->StoreProductCategory->save($this->data)) {
				$this->Session->setFlash(__d('store','The store product category has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__d('store','The store product category could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->StoreProductCategory->read(null, $id);
		}
		$storeProducts = $this->StoreProductCategory->StoreProduct->find('list');
		$storeCategories = $this->StoreProductCategory->StoreCategory->find('list');
		$this->set(compact('storeProducts', 'storeCategories'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__d('store','Invalid id for store product category', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->StoreProductCategory->delete($id)) {
			$this->Session->setFlash(__d('store','Store product category deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__d('store','Store product category was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>